import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:qunaimedical/models/consultation_record.dart';
import 'package:qunaimedical/pages/record_detail.dart';
import 'package:qunaimedical/utils/event_bus_manager.dart';
import 'package:qunaimedical/values/urls.dart';

/// 会诊大厅 item 样式
class ItemRecordPublish extends StatelessWidget {
  final ConsultationRecord item;

  const ItemRecordPublish({Key key, this.item}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (c) => RecordDetailPage(id: item.id),
          ),
        ).then((value) {
          eventBus.fire(EventBusManager(EventBusManager.favoriteRefresh));
        });
      },
      child: Container(
        height: 150,
        padding: EdgeInsets.symmetric(horizontal: 10),
        color: Colors.white,
        child: Row(
          children: [
            Container(
              margin: EdgeInsets.only(right: 10),
              child: ClipRRect(
                borderRadius: BorderRadius.circular(6),
                child: item.showImg == null || item.showImg == ''
                    ? Container(
                        child: Image.asset(
                          'assets/images/img_default_record.png',
                          fit: BoxFit.cover,
                        ),
                        width: 110,
                        height: 90,
                      )
                    : CachedNetworkImage(
                        imageUrl: '${Urls.BASE_URL}${item.showImg}',
                        width: 110,
                        height: 90,
                        fit: BoxFit.cover,
                        errorWidget: (c, url, error) => Container(
                          color: Colors.grey[200],
                          width: 110,
                          height: 90,
                        ),
                        placeholder: (c, url) => Container(
                          color: Colors.grey[200],
                          width: 110,
                          height: 90,
                        ),
                      ),
              ),
            ),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                mainAxisSize: MainAxisSize.min,
                children: [
                  Row(children: [
                    Text('会诊科室：', style: TextStyle(color: Colors.grey[700])),
                    Expanded(
                      child: Text(
                        item.sectionTypeName,
                        overflow: TextOverflow.ellipsis,
                      ),
                    )
                  ]),
                  Row(children: [
                    Text('会诊类型：', style: TextStyle(color: Colors.grey[700])),
                    Expanded(
                      child: Text(
                        item.consultationTypeName,
                        overflow: TextOverflow.ellipsis,
                      ),
                    )
                  ]),
                  Row(children: [
                    Text('会诊主题：', style: TextStyle(color: Colors.grey[700])),
                    Expanded(
                      child: Text(
                        item.title,
                        overflow: TextOverflow.ellipsis,
                      ),
                    )
                  ]),
                  Row(children: [
                    Text('预约时间：', style: TextStyle(color: Colors.grey[700])),
                    Expanded(
                      child: Text(
                        '${item.freeTime} ${item.morningAfternoon}',
                        overflow: TextOverflow.ellipsis,
                        style: Theme.of(context).textTheme.caption,
                      ),
                    )
                  ]),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
